﻿unit SetPhoneFrm;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  dxRibbonForm,
  Dialogs, cxGraphics, cxControls, cxLookAndFeels, cxLookAndFeelPainters,
  dxSkinsCore, dxSkinMcSkin, dxSkinSeven, dxSkinsdxRibbonPainter, cxClasses,
  dxRibbon,
  dxSkinOffice2010Black, dxSkinOffice2010Blue, dxSkinOffice2010Silver,
  cxPropertiesStore, dxSkinscxPCPainter, cxStyles, cxCustomData, cxFilter,
  cxData, cxDataStorage, cxEdit, DB, cxDBData, dxLayoutControl,
  dxLayoutcxEditAdapters, cxContainer, cxTextEdit, cxMaskEdit, cxDropDownEdit,
  cxLookupEdit, cxDBLookupEdit, cxDBLookupComboBox, cxGridLevel,
  cxGridCustomView, cxGridCustomTableView, cxGridTableView, cxGridDBTableView,
  cxGrid, JvDialogs, cxMRUEdit, JvBaseDlg, JvSelectDirectory, cxButtonEdit,
  Menus, dxLayoutLookAndFeels, StdCtrls, cxButtons, FIBDataSet, pFIBDataSet,
  dxmdaset, QImport3, QImport3DBF;

type
  TSetPhoneForm = class(Tdxcustomribbonform)
    Ribbon1Tab1: TdxRibbonTab;
    Ribbon1: TdxRibbon;
    prop1: TcxPropertiesStore;
    grp_root: TdxLayoutGroup;
    lcntr_root: TdxLayoutControl;
    v1: TcxGridDBTableView;
    l1: TcxGridLevel;
    grd1: TcxGrid;
    Itm_grd1: TdxLayoutItem;
    cbb_kontr: TcxLookupComboBox;
    Itm_cbb: TdxLayoutItem;
    grp_left: TdxLayoutGroup;
    grp2: TdxLayoutGroup;
    SelectDirectory1: TJvSelectDirectory;
    btn_dir: TcxButtonEdit;
    Itm_btnDir: TdxLayoutItem;
    btn_exec: TcxButton;
    Itm_btnExec: TdxLayoutItem;
    LSkin1: TdxLayoutLookAndFeelList;
    LCxSkin1: TdxLayoutCxLookAndFeel;
    DS_Kontragent: TpFIBDataSet;
    Source1: TDataSource;
    dbf1: TQImport3DBF;
    mt1: TdxMemData;
    Source2: TDataSource;
    clv1DBF_PHONE: TcxGridDBColumn;
    clv1DBF_FAMILY: TcxGridDBColumn;
    clv1DBF_IO: TcxGridDBColumn;
    clv1DBF_STREET: TcxGridDBColumn;
    clv1DBF_HOME: TcxGridDBColumn;
    clv1DBF_H_INDEX: TcxGridDBColumn;
    clv1DBF_ROOM: TcxGridDBColumn;
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure btn_dirPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure btn_execClick(Sender: TObject);
  private
    { Private declarations }
    procedure LoadDBF;
    procedure CreateMemTable;
    procedure SetMap;
  public
    { Public declarations }
  end;

var
  SetPhoneForm: TSetPhoneForm;

implementation

uses cmUtils, DModule;

{$R *.dfm}

procedure TSetPhoneForm.btn_dirPropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
 if SelectDirectory1.Execute then
 btn_dir.Text:=SelectDirectory1.Directory+'\';
end;

procedure TSetPhoneForm.btn_execClick(Sender: TObject);
begin
  LoadDBF;
end;
{-------------------------------------------------------------------------------
LoadDBF|Загружаем DBF файл
-------------------------------------------------------------------------------}
procedure TSetPhoneForm.LoadDBF;
begin
  dbf1.FileName:=btn_dir.Text+'KW2.DBF';
  SetMap;
  //dbf1.CharSet:=dcsOEM;
  dbf1.Execute;
end;

procedure TSetPhoneForm.SetMap;
begin

  with dbf1.Map do
  begin
    Add('DBF_PHONE=TELEPHONE');
    Add('DBF_FAMILY=FAMILY');
    Add('DBF_IO=IO');
    Add('DBF_STREET=STREET');
    Add('DBF_HOME=HOME');
    Add('DBF_H_INDEX=H_INDEX');
    Add('DBF_ROOM=ROOM');
  end;
end;
{-------------------------------------------------------------------------------
CreateMemTable|Создаем временную таблицу
-------------------------------------------------------------------------------}
procedure TSetPhoneForm.CreateMemTable;
begin
  with mt1.FieldDefs do
  begin
    CreateField(mt1,'DBF_PHONE',ftString,64);        // телефон
    CreateField(mt1,'DBF_FAMILY',ftString,256);      // фамилия
    CreateField(mt1,'DBF_IO',ftString,32);           // инициалы
    CreateField(mt1,'DBF_STREET',ftString,256);      // улица
    CreateField(mt1,'DBF_HOME',ftString,32);         // дом
    CreateField(mt1,'DBF_H_INDEX',ftString,6);       // индекс дома
    CreateField(mt1,'DBF_ROOM',ftString,10);         // квартира
    CreateField(mt1,'CODE',ftString);
    CreateField(mt1,'ADDR',ftString);
    CreateField(mt1,'ADDRNAME',ftString);
    CreateField(mt1,'KONTRAGENT',ftString);
    CreateField(mt1,'KONTRNAME',ftString);
    CreateField(mt1,'MASTER',ftString);
    CreateField(mt1,'STATE',ftSmallint);
    CreateField(mt1,'PHONE',ftString);
    CreateField(mt1,'PHONE1',ftString);
    CreateField(mt1,'PHONE2',ftString);
    CreateField(mt1,'PHONE3',ftString);
  end;
  mt1.Open;
end;

procedure TSetPhoneForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  RemoveBtn(Name);
  Action:=caFree;
end;

procedure TSetPhoneForm.FormCreate(Sender: TObject);
begin
  AddButton(self);
  LoadForm(prop1,Self.Name);
  DS_Kontragent.Open;
  CreateMemTable;
end;

end.
